package com.bytecodezz.app.base.extend.function

import java.util.regex.Pattern

/**
 * @author: bytecodezz
 * @version: 1.0
 * @time: 2021/8/16 18:11
 * @package: com.bytecodezz.app.base.extend.function
 *
 * @description:
 *
 */


fun Any.checkPhoneNumber(phone: String): Boolean {
    val matcher = Pattern.compile("\\d{11}").matcher(phone)
    return matcher.matches()
}

fun Any.checkPasswordRule(password: String, phone: String): Boolean {

    //数字
    val REG_NUMBER = ".*\\d+.*"
    //小写字母
    val REG_UPPERCASE = ".*[A-Z]+.*"
    //大写字母
    val REG_LOWERCASE = ".*[a-z]+.*"
    //特殊符号(~!@#$%^&*()_+|<>,.?/:;'[]{}\)
    val REG_SYMBOL = ".*[~!@#$%^&*()_+|<>,.?/:;'\\[\\]{}\"]+.*"
    //密码为空及长度大于8位小于30位判断
    if (password == null || password.length < 8) return false
    var i = 0
    if (password.matches(Regex(REG_NUMBER))) i++
    if (password.matches(Regex(REG_LOWERCASE))) i++
    if (password.matches(Regex(REG_UPPERCASE))) i++
    if (password.matches(Regex(REG_SYMBOL))) i++
    val contains = false
//                    password.contains(username);
    //                    password.contains(username);
    return !(i < 3 || contains)
}